/*
ANES replication material for:
"Personality and Roots of Welfare State Support: How Openness to Experience Moderates the Influence of Self-Interest and Ideology on Redistributive Preferences"

Authors: Tobias Heide-Jørgensen, Peter Thisted Dinesen, and Kim Mannemar Sønderskov.

PURPOSE: Reproducing results based on ANES data.
*/

*Reading and appending data
use "ANES2012_data.dta",clear

append using "ANES2016_data.dta"

gen wave=2012 if version=="ANES2012TimeSeries_version20160504"
replace wave=2016 if version=="ANES2016TimeSeries_20190904"

*Variable for openness
recode tipi_open V162337 (-9 -7 -6 -5=.),pre(new_)

recode tipi_conv V162342 (1=7) (2=6) (3=5) (5=3) (6=2) (7=1) (-9 -7 -6 -5=.),pre(new_)

gen open=new_tipi_open+new_tipi_conv
replace open=new_V162337+new_V162342 if wave==2016

sum open
replace open = (open-r(min))/(r(max)-r(min))	

alpha new_tipi_open new_tipi_conv //Alpha in 2012
alpha new_V162337 new_V162342 //Alpha in 2016

*Variable for extraversion
recode tipi_extra V162333 (-9 -7 -6 -5=.),pre(new_)

recode tipi_resv V162338 (1=7) (2=6) (3=5) (5=3) (6=2) (7=1) (-9 -7 -6 -5=.),pre(new_)

gen extrav=new_tipi_extra+new_tipi_resv
replace extrav=new_V162333+new_V162338 if wave==2016

sum extrav
replace extrav = (extrav-r(min))/(r(max)-r(min))	

alpha new_tipi_extra new_tipi_resv //Alpha in 2012
alpha new_V162333 new_V162338 //Alpha in 2016

*Variable for agreeableness
recode tipi_warm V162339 (-9 -7 -6 -5=.),pre(new_)

recode tipi_crit V162334 (1=7) (2=6) (3=5) (5=3) (6=2) (7=1) (-9 -7 -6 -5=.),pre(new_)

gen agree=new_tipi_crit+new_tipi_warm
replace agree=new_V162334+new_V162339 if wave==2016

sum agree
replace agree = (agree-r(min))/(r(max)-r(min))	

alpha new_tipi_crit new_tipi_warm //Alpha in 2012
alpha new_V162334 new_V162339 //Alpha in 2016

*Variable for conscientiousness
recode tipi_dep V162335 (-9 -7 -6 -5=.),pre(new_)

recode tipi_disorg V162340 (1=7) (2=6) (3=5) (5=3) (6=2) (7=1) (-9 -7 -6 -5=.),pre(new_)

gen cons=new_tipi_dep+new_tipi_disorg
replace cons=new_V162335+new_V162340 if wave==2016

sum cons
replace cons = (cons-r(min))/(r(max)-r(min))	

alpha new_tipi_dep new_tipi_disorg //Alpha in 2012
alpha new_V162335 new_V162340 //Alpha in 2016

*Variable for emotional stability
recode tipi_calm V162341 (-9 -7 -6 -5=.),pre(new_)

recode tipi_anx V162336 (1=7) (2=6) (3=5) (5=3) (6=2) (7=1) (-9 -7 -6 -5=.),pre(new_)

gen emo=new_tipi_anx+new_tipi_calm
replace emo=new_V162336+new_V162341 if wave==2016

sum emo
replace emo = (emo-r(min))/(r(max)-r(min))	

alpha new_tipi_anx new_tipi_calm //Alpha in 2012
alpha new_V162336 new_V162341 //Alpha in 2016

*Variable for attitudes toward redistribution
recode cses_govtact V162276 (1=5) (2=4) (4=2) (5=1) (-6 -7 -8 -9=.),pre(new_)

gen redis=new_cses_govtact
replace redis=new_V162276 if wave==2016

sum redis
replace redis = (redis-r(min))/(r(max)-r(min))	

*Variable for liberal-conservative self-identification
recode libcpre_self V161126 (99 -9 -8 -2=.),pre(new_)

gen ideo = new_libcpre_self
replace ideo = new_V161126 if wave==2016

sum ideo
replace ideo = (ideo-r(min))/(r(max)-r(min))	

label var ideo "Liberal/conservative identification"

*Variable for income
recode inc_incgroup_pre (1/4=1 "Under $15,000") (5/10=2 "$15,000-29,999") (11/14=3 "$30,000-49,999") (15/19=4 "$50,000-74,999") (20/22=5 "$75,000-99,999") (23/27=6 "$100,000-249,999") (28=7 "$250,000 or more") (-9 -8 -2 =.),gen(inc_12)

recode V165757 (1/4=1 "Under $15,000") (5/10=2 "$15,000-29,999") (11/14=3 "$30,000-49,999") (15/19=4 "$50,000-74,999") (20/22=5 "$75,000-99,999") (23/27=6 "$100,000-249,999") (28=7 "$250,000 or more") (-5 -2 =.),gen(inc_16)

recode V168023 (1=1 "Under $15,000") (2=2 "$15,000-29,999") (3=3 "$30,000-49,999") (4=4 "$50,000-74,999") (5=5 "$75,000-99,999") (6=6 "$100,000-249,999") (7=7 "$250,000 or more") (-9 -8 -1=.),gen(inc_16x)

gen inc=inc_12
replace inc=inc_16 if wave==2016
replace inc=inc_16x if wave==2016 & inc_16==.

label value inc inc_12

*Variable for sex
recode gender_respondent_x (2=0),pre(new_)
recode V161342 (2=0) (3 -9=.),pre(new_)

gen male = new_gender_respondent_x
replace male = new_V161342 if wave==2016

*Variable for education
recode  dem_edu (-9=.) (95=17 "Other"),pre(new_)
recode  V161270 (-9=.) (90 95=17 "Other"),pre(new_)

gen edu=new_dem_edu
replace edu=new_V161270 if wave==2016

label copy V161270 edu
label define edu -9 "" -8 "" 90 "" 95 "" 17 "Other", modify
label value edu edu

*Variable for age
recode dem_age_r_x V161267 (-2 -8 -9=.),pre(new_)

gen age=new_dem_age_r_x
replace age=new_V161267 if wave==2016

*Variable for marital status
recode dem_marital V161268 (-9=.), pre(new_)

gen marital= new_dem_marital
replace marital=new_V161268 if wave==2016

label copy V161268 marital
label define marital -9 "" 1 "Married: spouse present" 2 "Married: spouse absent" 3 "Widowed" 4 "Divorced" 5 "Separated" 6 "Never married", modify
label value marital marital

*Variable for race
recode dem_raceeth_x V161310x (-2 -9=.),pre(new_)

gen race=new_dem_raceeth_x
replace race=new_V161310x if wave==2016

label copy V161310x race
label define race -2 "", modify
label value race race

*Variable for occupation
gen employ=8 if dem_emptype_student==1
replace employ=7 if dem_emptype_hmaker==1
replace employ=6 if dem_emptype_disabled==1
replace employ=5 if dem_emptype_retire==1
replace employ=4 if dem_emptype_unemp==1
replace employ=2 if dem_emptype_layoff==1
replace employ=1 if dem_emptype_work==1

recode V161277 (-9=.),pre(new_)

replace employ= new_V161277 if wave==2016
recode employ (4=3) (5=4) (6=5) (7=6) (8=7)

label define employ 1 "Working now" 2 "Temporarily laid off" 3 "Unemployed" 4 "Retired" 5 "Permanently disabled" 6 "Homemaker" 7 "Student"
label value employ employ

*Variable for thermometer feelings
recode ftgr_liberals ftgr_cons V162097 V162101 (-9 -8 -7 -6 -2 998 999=.),pre(new_)

gen lib=new_ftgr_liberals
replace lib=new_V162097 if wave==2016

gen con=new_ftgr_cons
replace con=new_V162101 if wave==2016

*Variable for vote 
recode postvote_presvtwho (5=3) (-9 -7 -6 -1=.),pre(new_)
recode V162034a (3 4 5 7 9=3) (-9 -8 -7 -6 -1=.),pre(new_)

gen vote=new_postvote_presvtwho
replace vote=new_V162034a if wave==2016

*Variable for interview mode
gen in_mod=mode

replace in_mod=V160501 if wave==2016

*Variable for campaign interest
recode interest_following (-9 -8=.),pre(new_)

gen cinterest=new_interest_following
replace cinterest=V161004 if wave==2016

*Multiple imputations			
mi set flong							
							
mi register imputed redis ideo open inc emo extrav cons agree age male				
mi register regular	wave employ marital race edu lib con vote in_mod cinterest	

mi impute chained (ologit) inc (logit) male (reg) redis ideo open emo extrav cons age = wave employ marital race edu lib con vote in_mod cinterest, add(10) rseed(1234) augment force							
mi passive: gen inc_3_mi=.
mi passive: replace inc_3_mi=1 if inrange(inc,1,2)
mi passive: replace inc_3_mi=2 if inrange(inc,3,4)
mi passive: replace inc_3_mi=3 if inrange(inc,5,7)

label var inc_3_mi "Family income"

label define inc_3_mi 1 "Low income" 2 "Medium income" 3 "High income"
label values inc_3_mi inc_3_mi

*Primary analyses: income							
mi estimate, dots: reg redis inc_3_mi##c.open male i.edu c.age##c.age i.marital i.race i.employ emo extrav cons agree i.wave,robust
mi test 2.inc_3_mi#c.open 3.inc_3_mi#c.open

*Primary analyses: ideology							
mi estimate, dots: reg redis c.ideo##c.open i.inc male i.edu c.age##c.age i.marital i.race i.employ emo extrav cons agree i.wave,robust

*Analyses with other personality traits: income							
mi estimate, dots: reg redis inc_3_mi##c.cons male i.edu c.age##c.age i.marital i.race i.employ open extrav emo agree i.wave,robust

mi estimate, dots: reg redis inc_3_mi##c.emo male i.edu c.age##c.age i.marital i.race i.employ open extrav cons agree i.wave,robust

mi estimate, dots: reg redis inc_3_mi##c.extrav male i.edu c.age##c.age i.marital i.race i.employ open emo cons agree i.wave,robust

mi estimate, dots: reg redis inc_3_mi##c.agree male i.edu c.age##c.age i.marital i.race i.employ open extrav cons emo i.wave,robust

*Analyses with other personality traits: ideology							
mi estimate, dots: reg redis c.ideo##c.cons i.inc male i.edu c.age##c.age i.marital i.race i.employ open emo extrav agree i.wave,robust

mi estimate, dots: reg redis c.ideo##c.emo i.inc male i.edu c.age##c.age i.marital i.race i.employ open extrav cons agree i.wave,robust

mi estimate, dots: reg redis c.ideo##c.extrav i.inc male i.edu c.age##c.age i.marital i.race i.employ open emo cons agree i.wave,robust

mi estimate, dots: reg redis c.ideo##c.agree i.inc male i.edu c.age##c.age i.marital i.race i.employ open emo extrav cons i.wave,robust